package com.k1ccc0.alumniinformationmanagement.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.k1ccc0.alumniinformationmanagement.mapper.ActivityMapper;
import com.k1ccc0.alumniinformationmanagement.pojo.Activity;
import com.k1ccc0.alumniinformationmanagement.pojo.Alumni;
import com.k1ccc0.alumniinformationmanagement.pojo.PageBean;
import com.k1ccc0.alumniinformationmanagement.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public void activityUpload(Activity activity) {
        activity.setCreateTime(LocalDate.now());
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.insertAct(activity);
    }

    @Override
    public List<Activity> generateNoticeList() {
        return activityMapper.selectNoticeList();
    }

    @Override
    public List<Activity> generateSActList() {
        return activityMapper.selectSActList();
    }

    @Override
    public List<Activity> generateDActList() {
        return activityMapper.selectDActList();
    }

    @Override
    public Activity generateActDetail(Integer id) {
        return activityMapper.selectActivity(id);
    }

    @Override
    public PageBean selectActByPage(Integer page, Integer pageSize, String name, String publisher, String type, LocalDate begin, LocalDate end) {
        PageHelper.startPage(page,pageSize,true);
        List<Activity> actList = activityMapper.selectActList(name, publisher, type, begin, end);
        Page<Activity> p = (Page<Activity>) actList;
        //3、将两个结果封装到PageBean对象中
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public void deleteById(List<Integer> ids) {
        activityMapper.deleteById(ids);
    }


}
